#include "cardscene.h"
#include "cardviewobject.h"
#include <QDebug>
#include <QGraphicsEffect>

#include <QGraphicsSceneMouseEvent>

CardScene::CardScene(QObject *parent) :
    QGraphicsScene(parent)
{
}


void CardScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{

//    if (mouseEvent->button() != Qt::LeftButton)
//        return;

    QGraphicsScene::mousePressEvent(mouseEvent);
}

void CardScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
    QGraphicsScene::mouseMoveEvent(mouseEvent);
}

void CardScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
    if (mouseEvent->button() == Qt::RightButton)
    {
//        CardViewObject *card = new CardViewObject;
//        card->setPos(mouseEvent->scenePos());
//        this->addItem(card);
    }

    if (!this->selectedItems().isEmpty())
    {
        QGraphicsItem *card = this->selectedItems().at(0);        

        for ( int i = 0; i <  this->items().count();  ++i)
        {
            QGraphicsItem *itemc = this->items().at(i);
            if ((itemc->flags() && QGraphicsItem::ItemIsMovable) != 0)
            {
                QGraphicsBlurEffect *effect = new QGraphicsBlurEffect();
                itemc->setGraphicsEffect(effect);
            }
        }

        card->setGraphicsEffect(NULL);
    }
    else
    {
        for ( int i = 0; i <  this->items().count();  ++i)
        {
            QGraphicsItem *itemc = this->items().at(i);
            if ((itemc->flags() && QGraphicsItem::ItemIsMovable) != 0)
                itemc->setGraphicsEffect(NULL);
        }
    }
    QGraphicsScene::mouseReleaseEvent(mouseEvent);
}
